/*
 *  DataEntry.java 
 *    
 *    Copyright 2012 YAWP Project Team
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.googlecode.yawp.model;

import java.util.Calendar;

/**
 * This abstract class is intended to implement the shared components of data entries.
 * In particular, for YAWP, each entry has a date associated with it, which is covered
 * by this abstract class.
 * 
 * @author Dan Spuches
 *
 */
public abstract class DataEntry {
	
	private Calendar date;				// time-stamp for this entry
	
	/**
	 * Constructor for the DataEntry class that allows a Calendar object to be passed
	 * 
	 * @param date
	 */
	public DataEntry(Calendar date) {
		this.date = date;
	}
	
	/**
	 * Return a string representation of the date
	 * 
	 * @return The date of this entry
	 */
	public String getDateString() {		
		return getYear() + "-" + (getMonth() + 1) + "-" + getDay();
	}
	
	/**
	 * Returns a Calendar object representing the date for this WeightEntry
	 * 
	 * @return Calendar object representing the date for this WeightEntry
	 */
	public Calendar getDate() {
		return date;
	}
	
	/**
	 * Adjust the date for this entry 
	 * 
	 * @param date to set
	 */
	public void setDate(Calendar date) {
		this.date = date;
	}

	/**
	 * Return the year for this entry
	 * 
	 * @return The year for this entry
	 */
	public int getYear() {
		return date.get(Calendar.YEAR);
	}
	
	/**
	 * Return the month for this entry
	 * 
	 * @return The month for this entry
	 */
	public int getMonth() {
		return date.get(Calendar.MONTH);
	}
	
	/**
	 * Return the day of month for this entry
	 * 
	 * @return The day for this entry
	 */
	public int getDay() {
		return date.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * Helper method to convert inches to centimeters. 
	 * 
	 * @param inches Inches to convert
	 * @return Centimeter equivalent of inches
	 */
	public static double inchesToCentimeters(double inches) {
		return inches * 2.54;
	}
	
	/**
	 * Helper method to convert centimeters to inches. 
	 * 
	 * @param cm Centimeters to convert
	 * @return Inch equivalent of centimeters
	 */
	public static double centimetersToInches(double cm) {
		return cm / 2.54;
	}
	
	/**
	 * Helper method to convert pounds to kilograms
	 * 
	 * @param pounds Pounds to convert
	 * @return Kilogram equivalent of pounds
	 */
	public static double poundsToKilograms(double pounds) {
		return pounds / 2.20462262;
	}
	
	/**
	 * Helper method to convert kilograms to pounds
	 * 
	 * @param kg Kilograms to convert
	 * @return Pound equivalent of kilograms
	 */
	public static double kilogramsToPounds(double kg) {
		return kg * 2.20462262;
	}
	
}
